<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@taglib uri="/WEB-INF/fmt.tld" prefix="fmt"%>
<%@taglib uri="/WEB-INF/el.tld" prefix="el"%>
<%@taglib uri="/WEB-INF/fn.tld" prefix="fn"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<c:import url="/includes/css_inc.jsp"/>
		<c:import url="/includes/js_inc.jsp"/>
		<script>
			$(function(){
				$("#addBtn").button({
		            icons: {
		                primary: "ui-icon-plusthick"
		            }
				}).click(function(){
					$("#job").val("add");
					$("#searchForm").submit();
				});
				$("#btnSearch").button({
		            icons: {
		                primary: "ui-icon-search"
		            }
		        }).click(function(){
		        	dateFormat(document.getElementById("startDate"));
		        	dateFormat(document.getElementById("endDate"));
				});
		        $("[name=btnEdit]").button({
		            icons: {
		                primary: "ui-icon-pencil"
		            },
            		text: false
		        });
		        $("[name=btnDel]").button({
		            icons: {
		                primary: "ui-icon-closethick"
		            },
            		text: false
		        });
		        thaiDatepicker("startDate","#","1");
		        thaiDatepicker("endDate","#","1");

			});
			function edit(docNo){
				window.location='${pageContext.request.contextPath}/acc6?app=ACC60202&job=viewUpdate&documentNo='+docNo+'&isEdit=Y';
			}
			function del(docNo){
				if(confirm('คุณต้องการลบข้อมูลใช่หรือไม่?')==true){
					window.location='${pageContext.request.contextPath}/acc6?app=ACC60202&job=delete&documentNo='+docNo+'&budgetYear='+$("#budgetYear").val()+'&startDate='+$("#startDate").val()+'&endDate='+$("#endDate").val();
				}
			}
		</script>
	</head>
	<body>
		<c:set var="auth" value="${el:getMapValue(menuAuth, 'ACC60201')}"/>
		<c:import url="/apps/msg.jsp"/>
		<form class="acc67-form" name="searchForm" id="searchForm" action="${pageContext.request.contextPath}/acc6" method="post">
		<input type="hidden" name="app" id="app" value="ACC60201"/>
		<input type="hidden" name="job" id="job" value="search"/>
		<input type="hidden" name="proviceId" id="proviceId" value="${userInfo.areaCode}"/>
		<table width="100%" class="ui-widget ui-widget-content" border="0">
			<tr>
				<th align="left" class="acc67-header ui-widget-header" colspan="2"><b>${screenCode.ACC60201}</b></th>
			</tr>
			<tr>
				<td align="right" colspan="2">
					<c:if test="${fn:contains(auth, 'I')}">
						<button type="button" name="addBtn" id="addBtn" class="acc67-button">เพิ่มข้อมูล</button>
					</c:if>
				</td>
			</tr>
			<tr>
				<td width="20%" class="bold">จังหวัด : </td>
				<td>${userInfo.areaCodeName}</td>
			</tr>
			<tr>
				<td class="bold">ปีงบประมาณ : </td>
				<td>
					<select name="budgetYear" id="budgetYear">
						<option value="">----- เลือก -----</option>
							<c:if test="${!empty listBudgetYear}">
								<c:forEach var="data" items="${listBudgetYear}" varStatus="x">
									<c:if var="selected" test="${budgetYear == data.BUDGET_YEAR}"/>
									<option value="${data.BUDGET_YEAR}" ${selected ? 'selected' : ''}>${data.BUDGET_YEAR}</option>
								</c:forEach>
							</c:if>
					</select>
				</td>
			</tr>
			<tr>
				<td class="bold">วันที่รับเงิน : </td>
				<td>
					<input type="text" name="startDate" id="startDate" value="${startDate}"/>
					<input type="text" name="endDate" id="endDate" value="${endDate}"/>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<c:if test="${fn:contains(auth, 'S')}">
						<button type="submit" name="btnSearch" id="btnSearch">ค้นหาข้อมูล</button>
					</c:if>
				</td>
			</tr>
		</table>
		<br/>
		<c:if test="${!empty pageBean.pageData}">
			<fieldset>
				<legend>ผลการค้นหาข้อมูล</legend>
					<table width="100%" class="ui-widget ui-widget-content" border="0">
						<tr>
							<th align="center" class="ui-state-default"><b>ปีงบประมาณ<b/></th>
							<th align="center" class="ui-state-default"><b>เลขที่เอกสาร<b/></th>
							<th align="center" class="ui-state-default"><b>วันที่รับเงิน<b/></th>
							<th align="center" class="ui-state-default"><b>จำนวนเงิน<b/></th>
							<th align="center" class="ui-state-default"><b>คำอธิบายรายการ<b/></th>
							<th align="center" class="ui-state-default"><b>แก้ไข<b/></th>
							<th align="center" class="ui-state-default"><b>ลบ<b/></th>
						</tr>
					<c:forEach var="data" items="${pageBean.pageData}" varStatus="x">
						<tr class="grid-tr-${x.count % 2}">
							<td align="center">${data.BUDGET_YEAR}</td>
							<td align="center">${data.DOC_NO}</td>
							<td align="center">${el:dateTh(data.INCOME_DATE)}</td>
							<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${data.AMOUNT}" /></td>
							<td align="left">${data.INCOME_DESC}</td>
							<td align="center">
								<c:if test="${fn:contains(auth, 'U')}">
									<button type="button" name="btnEdit" id="btnEdit" class="acc67-button"  onclick="edit('${data.DOC_NO}')"/>
								</c:if>
							</td>
							<td align="center">
								<c:if test="${fn:contains(auth, 'D')}">
									<button type="button" name="btnDel" id="btnDel" class="acc67-button"  onclick="del('${data.DOC_NO}')"/>
								</c:if>		
							</td>
						</tr>
					</c:forEach>
					</table>
			</fieldset>
		</c:if>
		</form>
	</body>
</html>